import {Component, Input, OnInit} from '@angular/core';
import * as fa from '@fortawesome/free-solid-svg-icons';
import {isNullOrUndefined} from 'util';

@Component({
    selector: 'app-zero3-list-page',
    templateUrl: './zero3-list-page.component.html',
    styleUrls: ['./zero3-list-page.component.css']
})
export class Zero3ListPageComponent implements OnInit {

    @Input('table')
    table;

    page = {
        size: {
            value: 15,
            click: (event) => {
                switch (this.page.size.value) {
                    case 15:
                        this.page.size.value = 50;
                        this.table.data.page.size = 50;
                        break;
                    case 50:
                        this.page.size.value = 300;
                        this.table.data.page.size = 300;
                        break;
                    case 300:
                        this.page.size.value = 15;
                        this.table.data.page.size = 15;
                        break;
                }
                if (!isNullOrUndefined(this.table)) {
                    this.table.list();
                }
            }
        },
        first: {
            icon: fa.faAngleDoubleLeft,
            click: (event) => {
                this.table.data.page.number = 0;
                if (!isNullOrUndefined(this.table)) {
                    this.table.list();
                }
            }
        },
        previous: {
            icon: fa.faAngleLeft,
            click: (event) => {
                if (this.table.data.page.number > 0) {
                    this.table.data.page.number = this.table.data.page.number - 1;
                    if (!isNullOrUndefined(this.table)) {
                        this.table.list();
                    }
                }
            }
        },
        next: {
            icon: fa.faAngleRight,
            click: (event) => {
                if (this.table.data.page.number < this.table.data.page.totalPages - 1 ) {
                    this.table.data.page.number = this.table.data.page.number + 1;
                    if (!isNullOrUndefined(this.table)) {
                        this.table.list();
                    }
                }
            }
        },
        last: {
            icon: fa.faAngleDoubleRight,
            click: (event) => {
                this.table.data.page.number = this.table.data.page.totalPages - 1;
                if (!isNullOrUndefined(this.table)) {
                    this.table.list();
                }
            }
        }
    };

    constructor() {
    }

    ngOnInit() {
    }

}
